/**
 *用户相关信息
 * @author johnny
 * @date 2017/12/7 11:07
 */
layui.define(['layer', 'web'], function (exports) {
    var layer = layui.layer;
    var web = layui.web;
    var $ = layui.jquery;

    var obj = {
        /**
         * 判断用户是否登录,并返回 sessionId
         * @returns {*}
         */
        getSessionId: function () {
            var sessionId = "";

            web.load();
            var url = basePath + "/user/verifyLogin";
            web.ajax_sync(url, 'post', {}, function (data) {
                sessionId = data.result;
                if (sessionId == null || sessionId.length == 0) {
                    url = $("#casVerifyLogin").val();
                    web.ajax_cookie(url, 'post', {}, function (casdata) {
                        sessionId = casdata.result;
                        if (sessionId != null && sessionId.length > 0) {
                            url = basePath + "/user/saveCasLogin";
                            web.ajax_sync(url, 'post', {casId: sessionId}, function (data) {
                                // .....
                            });
                        }
                    });
                }
            });

            return sessionId;
        }

    };


    exports('user', obj);
});
